﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DoAn_BumTruong_DesignPattern.Controls
{
    public partial class Article : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        Facades arfacade = new Facades();
        private void LoadData()
        {
            string menuID = Request.QueryString["MenuID"] ?? "";
            string page = Request.QueryString["Page"] ?? "1";
            int howManyPage = 0;
            string search = "ngu dan 13 tuoi";
            //if (search != "")
            //{
            //    string fistPageUrl = Link.SearchArticle(search, "1");
            //    string pageUrl = Link.SearchArticle(search, "{0}");
            //    RepeaterArticle.DataSource = arfacade.PagingBySearchName(search, page, out howManyPage).OrderByDescending(ar => ar.ArticleID);
            //    RepeaterArticle.DataBind();
            //    PagesArticle.ShowPage(int.Parse(page), howManyPage, fistPageUrl, pageUrl, true);
            //}
            if (menuID != "")
            {
                string fistPageUrl = Link.ToMenu(menuID, "1");
                string pageUrl = Link.ToMenu(menuID, "{0}");
                RepeaterArticle.DataSource = arfacade.PagingArticleByMenu(menuID, page, out howManyPage).OrderByDescending(ar => ar.ArticleID);
                RepeaterArticle.DataBind();
                PagesArticle.ShowPage(int.Parse(page), howManyPage, fistPageUrl, pageUrl, true);
            }
            else
            {
                string fistPageUrl = Link.ToArticle("1");
                string pageUrl = Link.ToArticle("{0}");
                RepeaterArticle.DataSource = arfacade.PagingArticle(page, out howManyPage).OrderByDescending(ar => ar.ArticleID);
                RepeaterArticle.DataBind();
                PagesArticle.ShowPage(int.Parse(page), howManyPage, fistPageUrl, pageUrl, true);
            }
        }
    }
}